<template>
  <div class="saveUpdate">
    <el-dialog :close-on-click-modal="false" :title="has_done?'查看投诉':'处理投诉'" :visible.sync="showDialog" @close="$emit('update:showUpdate', false)"
               :showUpdate="showUpdate" width="500px">
      <el-form :model="DetailInfo" ref="saveChn" :disabled="!id" label-width="130px" size="mini">
        <dialog-wrapper :MaxWidth="400">
          <div v-if="!has_done">
            <el-form-item label="处理结果："  prop="remark" :rules="[{ required: true, message: '处理结果不能为空'}]">
              <el-input type="textarea" :maxlength="150" placeholder="不超过150个字" v-model="DetailInfo.remark" :rows="4"></el-input>
            </el-form-item>
          </div>
          <div v-else>
            <el-form-item label="处理结果：">
              <span>{{DetailInfo.remark}}</span>
            </el-form-item>
          </div>
        </dialog-wrapper>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="$emit('update:showUpdate', false)" size="small">关 闭</el-button>
        <el-button v-if="!has_done" type="primary" :loading="loading" @click="updateDetail" size="small">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import DialogWrapper from '@/components/DialogWrapper'
  import {getComplainById, replyComplainById} from '@/api'
import { open } from 'fs';
  import { getURL } from '@/api/img'
import { debuglog } from 'util';

  export default {
    components: {DialogWrapper},
    data() {
      return {
        setbank: false,
        showDialog: this.showUpdate,
        loading: false,
        white_ips: '',
        DetailInfo: {
          prologue: '亲，您好，下方按钮是目前可用充值方式，请点选您需要的充值方式',
          mch_ids: [],
          enable: true,
          use_vcode: false,
          white_ips: ''
        },
        complaint: '',
        img_list: []
      }
    },
    props: {
      showUpdate: {
        type: Boolean,
        default: false
      },
      id: {
        type: Number
      },
      has_done: {
        type: Boolean
      },
      MerchantsList: {
        type: Array
      },
      complaintTypes: {
        type: Array
      },
      agencyNickname: {
        type: String
      }
    },
    created() {
      if (this.id) {
        this.getDetail()
      }
    },
    methods: {
      updateDetail() {
        this.$refs.saveChn.validate(valid => {
          if (valid) {
            replyComplainById(this.id, {remark: this.DetailInfo.remark}).then(res => {
              if (res.status === 0) {
                this.$message({message: '处理成功。', type: 'success'})
                this.$emit('update:showUpdate', false)
              }
            })
          }
        })
      },
      getDetail() {
        getComplainById(this.id).then(res => {
          if (res.status === 0) {
            this.DetailInfo = res.data
            this.complaintTypes.forEach(item => {
              if (parseInt(res.data.complaint_types.toString()) === item.id) {
                this.complaint = item.value
              }
            })
          }
        })
        console.log(this.complaint)
      },
      openImage(item){
        const key =  item.split('?')[0];
            getURL(key).then(res=>{
              const d = res.data;
              if(d.status == 0){
                const url = d.data.urls[0].url;
                if(url) window.open(url,'__blank');
              }
          })
      }
    },
    watch: {
      showUpdate() {
        this.showDialog = this.showUpdate
      },
    }
  }
</script>

<style lang="scss" scoped>
.complain-img{
  max-width: 400px;
  max-height: 300px;
}
</style>
